﻿
$(document).ready(function () {
    $('.bar-chart').each(function () {
        var values = [];
        var data = jQuery.parseJSON($('pre', this).text());
        $(data, this).each(function () {
            var subset = [];
            for (var key in this) {
                subset.push([parseInt(this[key].Value), this[key].Key]);
            }
            values.push(subset);
        });
        $('pre', this).hide();
        var id = $('div', this).attr('id');
        var plot2 = $.jqplot(id, values, {
            seriesDefaults: {
                renderer: $.jqplot.BarRenderer,
                // Show point labels to the right ('e'ast) of each bar.
                // edgeTolerance of -15 allows labels flow outside the grid
                // up to 15 pixels.  If they flow out more than that, they 
                // will be hidden.
                pointLabels: { show: true, location: 'e', edgeTolerance: -15 },
                // Rotate the bar shadow as if bar is lit from top right.
                shadowAngle: 135,
                // Here's where we tell the chart it is oriented horizontally.
                rendererOptions: {
                    barDirection: 'horizontal'
                }
            },
            axes: {
                yaxis: {
                    renderer: $.jqplot.CategoryAxisRenderer
                }
            }

        });
    });
});